package com.dfqy.config;

import com.dfqy.interceptor.RoleInterceptor;
import com.dfqy.interceptor.TimeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author oldliu
 * @since 1.0
 */
@Configuration
public class DfqyConfig implements WebMvcConfigurer {
    @Autowired
    private RedisTemplate redisTemplate;
    @Override//不需要@bean注解
    public void addInterceptors(InterceptorRegistry registry) {
        TimeInterceptor t=new TimeInterceptor();//"/students.html","/js/**",
        registry.addInterceptor(t).excludePathPatterns("/**.css","/**/**.js","/**.html","/**.jpg","/**.png").addPathPatterns("/**");

        //设置redis
        RoleInterceptor role=new RoleInterceptor();//"/students.html","/js/**",
        role.setRedisTemplate(redisTemplate);
        registry.addInterceptor(role).excludePathPatterns("/**.css","/**/**.js","/**.html","/**.jpg","/**.png","/login/**","/login/gencode").addPathPatterns("/**");

    }
}
